package cn.xiaolang.common.utils;

/**
 * @author Dean
 * @date 2022-01-15
 */
public class FilterSpecialHtmlWords {
    /**
     * 对特殊的html字符进行编码
     *
     * @param message htmlContent
     * @return htmlContentFilter
     */
    public static String filter(String message) {

        if (message == null || message.length() == 0)
            return (null);
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < message.length(); i++) {
            switch (message.charAt(i)) {
                case '<':
                    result.append("&lt;");
                    break;
                case '>':
                    result.append("&gt;");
                    break;
                case '&':
                    result.append("&amp;");
                    break;
                case '"':
                    result.append("&quot;");
                    break;
                default:
                    result.append(message.charAt(i));
            }
        }
        return (result.toString());

    }

}